package com.example.day5.controller;

import com.example.day5.entity.Student;
import com.example.day5.service.impl.StuServiceImpl;
import com.example.day5.util.Result;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
public class StuController {
    @Resource
    StuServiceImpl stuService;
    @GetMapping({"/login","/login.html"})
    public String login()
    {
        return "login";
    }
    @PostMapping("/login")
    @ResponseBody
    public Result login(@RequestParam(value = "tname") String tname, @RequestParam(value = "tpwd") String tpwd)
    {
        Student stu=new Student(tname,tpwd);
        Student student=stuService.findByNameAndPwd(stu);
        if (student!=null)
        {
            return new Result(200, "登录成功", student);
        }
        else
        {
            return new Result(400,"登录失败",null);
        }
    }
    @GetMapping("/index")
    public String index()
    {
        return "index";
    }
}

